package com.jubotech.business.web.controller.admin;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jubotech.business.web.domain.WxAccountInfo;
import com.jubotech.business.web.query.DeviceQuery;
import com.jubotech.business.web.service.WxAccountService;
import com.jubotech.framework.common.DispatchMode;
import com.jubotech.framework.common.GridPage;
import com.jubotech.framework.common.ResultInfo;

@Controller
@RequestMapping("/admin")
public class DeviceStateController {

	@Autowired
	private WxAccountService service;

	@RequestMapping("/device/{mode}/dispatch")
	public ModelAndView dispatch(HttpServletRequest request, @PathVariable String mode, Integer id) {
		Map<String, Object> model = new HashMap<>();
		model.put("mode", mode);
		if (DispatchMode.LIST_MODE.equals(mode)) {
			return new ModelAndView("/admin/device/list", model);
		}

		return new ModelAndView("/common/error");
	}

	@PostMapping("/device/pageList")
	@ResponseBody
	public ResultInfo pageList(HttpServletRequest request, DeviceQuery query) {
		GridPage<WxAccountInfo> gridPage = new GridPage<>(service.pageList(query));
		return ResultInfo.success(gridPage);
	}

}
